module.exports = function(Mogo) {
  const State = Mogo.State;
  Mogo.User = {
    // 当前用户
    current: function() {
      return State.get("mogoUser");
    },
    // 注册
    async register(params) {
      const user = new Mogo.Model("User");
      return await user.execute("register", params);
    },
    // 登陆
    async login(params) {
      const user = new Mogo.Model("User");
      let res = await user.execute("login", params);
      State.set("mogoUser", res);
      return res;
    },
    async checkUserLogin() {
      const user = new Mogo.Model("User");
      return await user.execute("userStatus");
    },
    // 请求手机验证码
    async requestSmsCode(params) {
      const user = new Mogo.Model("User");
      return await user.execute("requestSmsCode", params);
    },
    // 退出登陆
    async logout() {
      State.set("mogoUser", null);
      return Promise.resolve("退出成功");
    }
  };
};
